﻿using Core.Infrastructure.AnimationService;
using Core.Infrastructure.Constants;
using Core.Infrastructure.EventArgs;
using Core.Infrastructure.ModuleBase;
using Core.Infrastructure.ScreenManager;
using Core.Infrastructure.Settings;
using Core.ScreenStore.Screen;
using Core.ScreenStore.ScreenFactory;
using Microsoft.Practices.Composite.Events;
using Microsoft.Practices.Unity;

namespace Core.ScreenStore
{
    public class ScreenStoreModule : ModuleBase
    {
        private IUnityContainer _container;
        private IScreenFactoryRegistry _screenFactoryRegistry;

        public ScreenStoreModule(IUnityContainer container,
                                 IScreenFactoryRegistry screenFactoryRegistry,
                                 IEventAggregator eventAggregator,
                                 IAnimationService animationService,
                                 ISettings settings)
            : base(container, screenFactoryRegistry)
        {
            _container = container;
            _screenFactoryRegistry = screenFactoryRegistry;
            EventAggregator = eventAggregator;
            AnimationService = animationService;
            Settings = settings;
        }

        protected IEventAggregator EventAggregator { get; set; }
        protected IAnimationService AnimationService { get; set; }
        public ISettings Settings { get; set; }

        public override void Initialize()
        {
            base.Initialize();
            LoadStartPage();
        }

        private void LoadStartPage()
        {
            var screenEventArgs = new ScreenEventArgs
                                      {
                                          ScreenType = ScreenType.ArticlesScreen,
                                          RegionName = RegionConstants.RegionMainArea,
                                          PerformAnimation = true
                                      };
            this.EventAggregator.GetEvent<ScreenActivateEvent>().Publish(screenEventArgs);
        }

        protected override void RegisterScreenFactories()
        {
            this.ScreenFactoryRegistry.Register(ScreenType.ArticlesScreen,
                                                typeof(GenericScreenFactory<ArticlesScreen>));

            this.ScreenFactoryRegistry.Register(ScreenType.ArticleDetailsScreen,
                                               typeof(GenericScreenFactory<ArticleDetailsScreen>));

            this.ScreenFactoryRegistry.Register(ScreenType.ThemeSelectScreen, 
                                                typeof(GenericScreenFactory<ThemeSelectScreen>));
        }

        protected override void RegisterViewsAndServices()
        {
        }
    }
}
